package com.jl.jlapp.mvp.fragment;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemChildClickListener;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.GoodsListAdapter;
import com.jl.jlapp.eneity.GoodsListModel;
import com.jl.jlapp.eneity.GoodsListModel.ResultDataBean;
import com.jl.jlapp.eneity.GoodsListModel.ResultDataBean.GoodsSpecificationDetailsBean;
import com.jl.jlapp.eneity.PostModel;
import com.jl.jlapp.mvp.activity.GoodsDetailActivity;
import com.jl.jlapp.mvp.activity.LoginActivity;
import com.jl.jlapp.mvp.activity.SearchGoodsListActivity;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.nets.Transformer;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.ArrayList;
import java.util.List;

public class GoodsListFragment extends Fragment {
    public static final String TAG = "aaaaaGoodsListFragment";
    public String brandName = "all";
    public Integer classificationId = Integer.valueOf(0);
    GoodsListAdapter goodsListAdapter;
    List<GoodsListModel.ResultDataBean> goodsListModels = new ArrayList();
    public String isHasGoods = "true";
    public double maxPrice = 0.0D;
    public double minPrice = 0.0D;
    public String priceSort = "";
    private ProgressDialog progressDialog;
    SearchGoodsListActivity searchGoodsListActivity;
    @BindView(R.id.show_goods_list_view)
    RecyclerView showGoodsListView;
    public Integer sortType = Integer.valueOf(1);
    int userId = 0;
    public String userSearchWorld = "";
    View view;

    public void buildProgressDialog() {
        if (this.progressDialog == null) {
            this.progressDialog = new ProgressDialog(getContext());
            this.progressDialog.setProgressStyle(0);
        }
        this.progressDialog.setMessage("加载中");
        this.progressDialog.setCancelable(true);
        this.progressDialog.show();
    }

    public void cancelProgressDialog() {
        if ((this.progressDialog != null) && (this.progressDialog.isShowing())) {
            this.progressDialog.dismiss();
        }
    }

    public void getGoodsList(int paramInt1, String paramString1, String paramString2, String paramString3, Double paramDouble1, Double paramDouble2, String paramString4, int paramInt2) {
        Net.get().getGoodsList(paramInt1, paramString1, paramString2, paramString3, paramDouble1, paramDouble2, paramString4, paramInt2)
                .compose(Transformer.<GoodsListModel>switchSchedulers())
                .subscribe(new CommonObserver<GoodsListModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(GoodsListModel goodsListModel) {

                    }
                });

    }

    public void insertShoppingCart(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, Integer paramInteger4) {
        Net.get().insertShoppingCart(paramInteger1.intValue(), paramInteger2.intValue(), paramInteger3.intValue(), paramInteger4.intValue(), 0, "")
                .compose(Transformer.<PostModel>switchSchedulers())
                .subscribe(new CommonObserver<PostModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(PostModel postModel) {

                    }
                });

    }

    public void onAttach(Activity paramActivity) {
        super.onAttach(paramActivity);
        this.searchGoodsListActivity = ((SearchGoodsListActivity) getActivity());
        this.userSearchWorld = this.searchGoodsListActivity.mSearchWorld;
        this.priceSort = this.searchGoodsListActivity.priceSort;
        this.sortType = this.searchGoodsListActivity.sortType;
        this.isHasGoods = this.searchGoodsListActivity.isHasGoods;
        this.minPrice = this.searchGoodsListActivity.minPrice;
        this.maxPrice = this.searchGoodsListActivity.maxPrice;
        this.brandName = this.searchGoodsListActivity.brandName;
        this.classificationId = this.searchGoodsListActivity.classificationId;
        Log.d("aaaaaGoodsListFragment", "sortType:" + this.sortType + " priceSort:" + this.priceSort + " userSearchWorld:" + this.userSearchWorld + " isHasGoods:" + this.isHasGoods + " minPrice:" + this.minPrice + " maxPrice:" + this.maxPrice + " brandName:" + this.brandName + " classificationId:" + this.classificationId);
    }

    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
        this.view = paramLayoutInflater.inflate(R.layout.fragment_goods_list, null, false);
        ButterKnife.bind(this, this.view);
        Log.d("aaaaaGoodsListFragment", "userSearchWorld:" + this.userSearchWorld);
        return this.view;
    }

    public void onResume() {
        super.onResume();
        this.userId = getContext().getSharedPreferences("JLAppData", 0).getInt("userId", 0);
        buildProgressDialog();
        getGoodsList(this.sortType.intValue(), this.priceSort, this.userSearchWorld, this.isHasGoods, Double.valueOf(this.minPrice), Double.valueOf(this.maxPrice), this.brandName, this.classificationId.intValue());
    }

    public void setAdapter() {
        if (this.goodsListAdapter == null) {
            this.showGoodsListView.setLayoutManager(new LinearLayoutManager(getContext()));
            this.goodsListAdapter = new GoodsListAdapter(R.layout.goods_list_item, this.goodsListModels);
            this.showGoodsListView.setAdapter(this.goodsListAdapter);
            this.goodsListAdapter.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                    int parseInt = Integer.parseInt((String) ((TextView) paramAnonymousView.findViewById(R.id.goods_id)).getText());
                    Log.d("aaaaaaaaaaa", "goodsId:" + parseInt);
                    Intent intent = new Intent(GoodsListFragment.this.getContext(), GoodsDetailActivity.class);
                    intent.putExtra("goodsId", parseInt);
                    GoodsListFragment.this.startActivity(intent);
                }
            });
            this.goodsListAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
                public void onItemChildClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                    if (GoodsListFragment.this.userId > 0) {
                        GoodsListFragment.this.insertShoppingCart(Integer.valueOf(GoodsListFragment.this.userId), Integer.valueOf(((GoodsListModel.ResultDataBean) GoodsListFragment.this.goodsListModels.get(paramAnonymousInt)).getId()), Integer.valueOf(((GoodsListModel.ResultDataBean.GoodsSpecificationDetailsBean) ((GoodsListModel.ResultDataBean) GoodsListFragment.this.goodsListModels.get(paramAnonymousInt)).getGoodsSpecificationDetails().get(0)).getId()), Integer.valueOf(1));
                        return;
                    }
                    Toast.makeText(GoodsListFragment.this.getContext(), "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(GoodsListFragment.this.getContext(), LoginActivity.class);
                    GoodsListFragment.this.startActivity(intent);
                }
            });
            return;
        }
        this.goodsListAdapter.notifyDataSetChanged();
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/fragment/GoodsListFragment.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */